<template>
  <div class="main">
    <myForm
      :dataForm="dataForm"
      :isLook="isLook"
      :formItem="formItem"
      :confimText="'确定'"
      @cancel="cancel"
      @handleSubmit="handleSubmit"
    />
  </div>
</template>

<script>
import myForm from '../record/components/myForm.vue';
import { forgetPwd } from '@/api/user.js';
import { Md5 } from 'ts-md5/dist/md5';

export default {
  components: { myForm },
  props: {
    dataForm: {
      type: Object,
      default: () => {
        return {};
      }
    },
    isLook: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      formItem: [
        {
          key: 'userAccount',
          label: '手机号',
          propsType: 'input'
        },
        {
          key: 'code',
          label: '验证码',
          propsType: 'phoneCode'
        },
        {
          key: 'newPassword',
          label: '新密码',
          propsType: 'password'
        },
        {
          key: 'confirmPassword',
          label: '确认密码',
          propsType: 'password'
        }
      ]
    };
  },
  methods: {
    handleSubmit(values) {
      values.newPassword = Md5.hashStr(values.newPassword);
      values.confirmPassword = Md5.hashStr(values.confirmPassword);
      forgetPwd(values).then(res => {
        if (res.code == 0) {
          this.$message.success('修改成功');
          this.$emit('cancel');
        }
      });
    },
    cancel() {
      this.$emit('cancel');
    }
  }
};
</script>

<style scoped lang="scss"></style>
